import { tajax } from '../js/tajax'

export function updatePosition(longitude, latitude) {
    tajax({
        url: '/deliverer/position/update',
        method: 'post',
        data: {
            longitude: longitude,
            latitude: latitude
        },
        success: function (data) {
        },
        error: function (data) {
        }
    });
}

export function getPosition(result) {
    tajax({
        url: '/deliverer/position/get',
        method: 'get',
        success: function (data) {
            if (data.code == 0) {
                result(data.data)
            }
        }
    });
}

export function takeOrder(orderId) {
    tajax({
        url: '/deliverer/order/take',
        method: 'post',
        data: {
            orderId: orderId
        },
        success: function (data) {
            alert(data.data)
            window.location.reload()
        },
        error: function (data) {
            alert(data.message)
        }
    });
}

export function arriveOrder(orderId) {
    tajax({
        url: '/deliverer/order/arrive',
        method: 'post',
        data: {
            orderId: orderId
        },
        success: function (data) {
            alert(data.data)
            window.location.reload()
        },
        error: function (data) {
            alert(data.message)
        }
    });
}

export function deliverOrder(orderId) {
    tajax({
        url: '/deliverer/order/deliver',
        method: 'post',
        data: {
            orderId: orderId
        },
        success: function (data) {
            alert(data.data)
            window.location.reload()
        },
        error: function (data) {
            alert(data.message)
        }
    });
}

export function receiveOrder(orderId) {
    tajax({
        url: '/deliverer/order/receive',
        method: 'post',
        data: {
            orderId: orderId
        },
        success: function (data) {
            alert(data.data)
            window.location.reload()
        },
        error: function (data) {
            alert(data.message)
        }
    });
}


export function allOrders(result) {
    tajax({
        url: '/deliverer/order/all',
        method: 'post',
        success: function (data) {
            if (data.code == 0) {
                result(data.data)
            } else {
                result([])
            }
        },
        error: function (data) {
            alert(data.message)
        }
    });
}

function getOrder(orderId) {
    tajax({
        url: '/deliverer/order/get',
        method: 'post',
        data: {
            orderId: orderId
        },
        success: function (data) {

        }
    });
}

export function availableOrders(result) {
    tajax({
        url: '/deliverer/order/available',
        method: 'get',
        success: function (data) {
            if (data.code == 0) {
                result(data.data)
            } else {
                result([])
            }
        },
        error: function (data) {
            alert(data.message)
        }
    });
}